﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using log4net;
using System.Reflection;

namespace AnyOffice.general.system.rtx
{
    public partial class rtx_config : ModulePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);//readonly

       

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                string assemblyFile = Server.MapPath("/bin/RTX.dll");
                try
                {
                    Type type = Assembly.LoadFrom(assemblyFile).GetType("RTX.RtxConfiguration", true);
                    object obj2 = Activator.CreateInstance(type);
                    object obj3 = type.GetMethod("IsSdkOk").Invoke(obj2, null);
                    if ((obj3 != null) && !Convert.ToBoolean(obj3.ToString()))
                    {
                        this.pnlMain.Visible = false;
                        this.litMessage.Text = base.ShowPrompt("RTX Server SDK 没有正确安装或者出现了问题，需要重新安装。", "rtx_config.aspx");
                        return;
                    }
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("RTX", exception);
                    }
                }
                try
                {
                    Assembly assembly2 = Assembly.LoadFrom(assemblyFile);
                    Type type2 = assembly2.GetType("RTX.RtxConfiguration", true);
                    object obj4 = Activator.CreateInstance(type2);
                    object obj5 = type2.GetProperty("Enabled", Type.GetType("System.Boolean")).GetValue(obj4, null);
                    if (obj5 != null)
                    {
                        this.ckbEnabled.Checked = Convert.ToBoolean(obj5);
                    }
                    object obj6 = type2.GetProperty("RtxServerIp", Type.GetType("System.String")).GetValue(obj4, null);
                    if (obj5 != null)
                    {
                        this.txtRtxServerIp.Text = obj6.ToString();
                    }
                    object obj7 = type2.GetProperty("RtxPort", Type.GetType("System.Int32")).GetValue(obj4, null);
                    if (obj7 != null)
                    {
                        this.txtRtxPort.Text = obj7.ToString();
                    }
                    object obj8 = type2.GetProperty("UserSync", Type.GetType("System.Boolean")).GetValue(obj4, null);
                    if (obj8 != null)
                    {
                        this.ckbUserSync.Checked = Convert.ToBoolean(obj8);
                    }
                    object obj9 = type2.GetProperty("SmsRemind", Type.GetType("System.Boolean")).GetValue(obj4, null);
                    if (obj9 != null)
                    {
                        this.ckbSmsRemind.Checked = Convert.ToBoolean(obj9);
                    }
                    object obj10 = type2.GetProperty("DelayTime", Type.GetType("System.Int32")).GetValue(obj4, null);
                    if (obj10 != null)
                    {
                        this.txtDelayTime.Text = obj10.ToString();
                    }
                    Type type3 = assembly2.GetType("RTX.RtxSdk", true);
                    object obj11 = Activator.CreateInstance(type3);
                    object obj12 = type3.GetProperty("SdkServerIp", Type.GetType("System.String")).GetValue(obj11, null);
                    if (obj12 != null)
                    {
                        this.txtSdkServerIp.Text = obj12.ToString();
                    }
                    object obj13 = type3.GetProperty("SdkPort", Type.GetType("System.Int32")).GetValue(obj11, null);
                    if (obj13 != null)
                    {
                        this.txtSdkPort.Text = obj13.ToString();
                    }
                }
                catch (Exception exception2)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("RTX", exception2);
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                try
                {
                    this.pnlMain.Visible = false;
                    Assembly assembly3 = Assembly.LoadFrom(Server.MapPath("/bin/RTX.dll"));
                    Type type4 = assembly3.GetType("RTX.RtxConfiguration", true);
                    object obj14 = Activator.CreateInstance(type4);
                    type4.GetProperty("Enabled", Type.GetType("System.Boolean")).SetValue(obj14, this.ckbEnabled.Checked, null);
                    type4.GetProperty("RtxServerIp", Type.GetType("System.String")).SetValue(obj14, this.txtRtxServerIp.Text, null);
                    type4.GetProperty("RtxPort", Type.GetType("System.Int32")).SetValue(obj14, Convert.ToInt32(this.txtRtxPort.Text), null);
                    type4.GetProperty("UserSync", Type.GetType("System.Boolean")).SetValue(obj14, this.ckbUserSync.Checked, null);
                    type4.GetProperty("SmsRemind", Type.GetType("System.Boolean")).SetValue(obj14, this.ckbSmsRemind.Checked, null);
                    type4.GetProperty("DelayTime", Type.GetType("System.Int32")).SetValue(obj14, Convert.ToInt32(this.txtDelayTime.Text), null);
                    Type type5 = assembly3.GetType("RTX.RtxSdk", true);
                    object obj15 = Activator.CreateInstance(type5);
                    type5.GetProperty("SdkServerIp", Type.GetType("System.String")).SetValue(obj15, this.txtSdkServerIp.Text, null);
                    type5.GetProperty("SdkPort", Type.GetType("System.Int32")).SetValue(obj15, Convert.ToInt32(this.txtSdkPort.Text), null);
                    this.litMessage.Text = base.ShowPrompt("RTX参数设置保存成功！", "rtx_config.aspx");
                }
                catch (Exception exception3)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("RTX", exception3);
                    }
                    this.litMessage.Text = base.ShowPrompt("RTX参数设置保存失败：详细信息请查看日志！", "rtx_config.aspx");
                }
            }
        } 

    }
}
